<?php

namespace App\Models;


class Drag extends Orm
{
    //
    protected $table = 'dragon';
    protected $dateFormat = 'U';
    public $timestamps = true;


    public function publishUserInfo()
    {
        return $this->hasOne(Users::class, 'id', 'user_id');
    }

    public function goodsList()
    {
        return $this->hasMany(DragDetail::class, 'drag_id')->where('valid',1);
    }

    //方便前端价格显示从小到大
    public function goodsList2()
    {
        return $this->hasMany(DragDetail::class, 'drag_id')->where('valid',1)->orderBy('price');
    }

    public function subscribe()
    {
        return $this->hasOne(Subscribe::class, 'publish_user_id', 'user_id');
    }

    public function setStartTimeAttribute($value)
    {
        $this->attributes['start_time'] = strtotime($value);
    }

    public function setEndTimeAttribute($value)
    {
        $this->attributes['end_time'] = strtotime($value);
    }

    public function getStartTimeAttribute()
    {
        return date('Y-m-d H:i', $this->attributes['start_time']);
    }

    public function getEndTimeAttribute()
    {
        return date('Y-m-d H:i', $this->attributes['end_time']);
    }

    public function orderList()
    {
        return $this->hasMany(Order::class,'dragon_id','id');
    }
}
